package com.longrise.android.byjk.plugins.tabfirst;

import android.webkit.JavascriptInterface;

import com.longrise.common.base.RxManager;
import com.longrise.common.base.web.BaseWebActivity;
import com.longrise.common.base.web.BaseWebBridge;

import io.reactivex.Observable;
import io.reactivex.ObservableEmitter;
import io.reactivex.ObservableOnSubscribe;
import io.reactivex.android.schedulers.AndroidSchedulers;
import io.reactivex.disposables.Disposable;
import io.reactivex.functions.Consumer;

/**
 * Created by Administrator on 2018/3/12.
 * 电子名片的bridge
 */

class PersonShowBridge2 extends BaseWebBridge {

    public PersonShowBridge2(BaseWebActivity activity, RxManager rxManager) {
        super(activity, rxManager);
    }

    @JavascriptInterface
    public void editData() {
        Disposable subscribe = Observable.create(new ObservableOnSubscribe<String>() {
            @Override
            public void subscribe(ObservableEmitter<String> e) throws Exception {
                e.onNext("1111");
                e.onComplete();
            }
        }).observeOn(AndroidSchedulers.mainThread())
                .subscribe(new Consumer<String>() {
                    @Override
                    public void accept(String s) throws Exception {
                        ((PersonalShowActivity2) mActivity).startActivity();
                    }
                });
        mRxManager.addDisposable(subscribe);

    }

    @JavascriptInterface
    public void bindingPhoneNumber() {
        Disposable subscribe = Observable.create(new ObservableOnSubscribe<String>() {
            @Override
            public void subscribe(ObservableEmitter<String> e) throws Exception {
                e.onNext("2222");
                e.onComplete();
            }
        }).observeOn(AndroidSchedulers.mainThread())
                .subscribe(new Consumer<String>() {
                    @Override
                    public void accept(String s) throws Exception {
                        ((PersonalShowActivity2) mActivity).startActivity();
                    }
                });
        mRxManager.addDisposable(subscribe);

    }

    @JavascriptInterface
    public void uploadHeadImage() {
        Disposable subscribe = Observable.create(new ObservableOnSubscribe<String>() {
            @Override
            public void subscribe(ObservableEmitter<String> e) throws Exception {
                e.onNext("3333");
                e.onComplete();
            }
        }).observeOn(AndroidSchedulers.mainThread())
                .subscribe(new Consumer<String>() {
                    @Override
                    public void accept(String s) throws Exception {
                        ((PersonalShowActivity2) mActivity).uploadUserImg();
                    }
                });
        mRxManager.addDisposable(subscribe);

    }

    @JavascriptInterface
    public void changeFace() {
        Disposable subscribe = Observable.create(new ObservableOnSubscribe<String>() {
            @Override
            public void subscribe(ObservableEmitter<String> e) throws Exception {
                e.onNext("4444");
                e.onComplete();
            }
        }).observeOn(AndroidSchedulers.mainThread())
                .subscribe(new Consumer<String>() {
                    @Override
                    public void accept(String s) throws Exception {
                        ((PersonalShowActivity2) mActivity).jump2BackWallActivity();
                    }
                });
        mRxManager.addDisposable(subscribe);

    }

}